package be.novelfaces.test.common;

import static org.easymock.EasyMock.expect;

import java.util.HashMap;
import java.util.Map;

import javax.faces.component.UIComponent;

import org.junit.runner.Description;

public class MockFacesEnvironmentWithComponentRule<T extends UIComponent> extends MockFacesEnvironmentRule {

	private T uiComponentMock;
	private Map<String, Object> attributesMap;

	public MockFacesEnvironmentWithComponentRule(Class<T> uiComponentClass) {
		this.uiComponentMock = getEnvironment().createMock(uiComponentClass);
	}

	@Override
	protected void starting(Description description) {
		super.starting(description);
		// set up attributes map
		attributesMap = new HashMap<String, Object>();
		expect(uiComponentMock.getAttributes())
				.andStubReturn(attributesMap);
	}

	@Override
	protected void finished(Description description) {
		super.finished(description);
		uiComponentMock = null;
		attributesMap = null;
	}

	public T getUIComponentMock() {
		return uiComponentMock;
	}
	
	public Map<String, Object> getAttributesMap() {
		return attributesMap;
	}

}
